<?php
/**
 * Created by PhpStorm.
 * User: 王文凡<787802868@qq.com>
 * Date: 2016/9/20 0020
 * Time: 14:21
 */

namespace Common\Model;
use Think\Model;

class LinetypesModel extends Model
{

    protected $_validate = [
        ['line_name', 'require', '线条型号名称必须填写！'],
        ['line_name', '', '线条型号名称已经存在！', 0, 'unique', 1]
    ];

    //新增或更新工艺信息
    public function addCraft($id='')
    {

        if(!$this->create()){
            $arr['state']='error';
            $arr['info']=$this->getError();
            return $arr;
        }else{
            if(empty($id)){
                $_POST['create_time']=time();
                if($this->add($_POST)){
                    $arr['state']='success';
                    $arr['info']='新增成功';
                }else{
                    $arr['state']='error';
                    $arr['info']='新增失败';
                }
                return $arr;
            }else{
                //更新数据
                if($this->where("id=%d",$id)->save($_POST)){
                    $arr['state']='success';
                    $arr['info']='更新成功';
                }else{
                    $arr['state']='error';
                    $arr['info']='更新失败';
                }
                return $arr;
            }
        }

    }

    //查询工艺信息
    public function lineList()
    {
        $list=$this->where("status=%d",1)->select();
        return oneL($list);
    }
}